﻿using System;
using System.Configuration;
using System.Xml;

namespace Alex.Library.Log.Configuration
{
    /// <summary>
    /// 日志输出级别元素
    /// </summary>
    public class FlushLevelContentElement : EnumContentElement<LogLevel>
    {
        /// <summary>
        /// 默认构造函数
        /// </summary>
        public FlushLevelContentElement()
        {
            this.Value = LogLevel.DEBUG;
        }

        /// <summary>
        /// 从配置信息中反序列化内容s
        /// </summary>
        /// <param name="reader"></param>
        /// <param name="serializeCollectionKey"></param>
        protected override void DeserializeElement(XmlReader reader, bool serializeCollectionKey)
        {
            LogLevel level = LogLevel.DEBUG;
            object obj = reader.ReadElementContentAsString();
            if (obj != null)
            {
                Enum.TryParse<LogLevel>(obj.ToString(), out level);
            }
            this.Value = level;
        }        
    }
}
